#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "singleton.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    
    //testThread = TestThreadInstance;
    //connect(testThread, &TestThread::frameReady, this, &MainWindow::updatePixmap);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_startBtn_clicked()
{
    if (testThread == nullptr) {
        testThread = new TestThread;
        connect(testThread, &TestThread::frameReady, this, &MainWindow::updatePixmap);
        testThread->start();
    }
    else {
        testThread->start();
    }
    
}


void MainWindow::on_endBtn_clicked()
{
    if(testThread==nullptr) {
        return;
    }

    testThread->exitThread();

    testThread->wait();

    delete testThread;

    testThread = nullptr;


}

void MainWindow::updatePixmap(const QPixmap& pixmap)
{
    ui->label->setPixmap(pixmap);
}




